cmake_minimum_required(VERSION 3.5.1)

set(MODULE_NAME "FinalMod")
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
    set(${MODULE_NAME}_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/include")
    set(${MODULE_NAME}_LIBRARIES ${MODULE_NAME})
else()
    set(${MODULE_NAME}_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE)
    set(${MODULE_NAME}_LIBRARIES ${MODULE_NAME} PARENT_SCOPE)
endif(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/include
)

add_library(${MODULE_NAME} 
    "src/FinalMod.c"
    "src/ModBuildin.c"
)

target_link_libraries(${MODULE_NAME}
    dl
)

# add_subdirectory(lib/FinalMod)
# target_include_directories(${MODULE_NAME} PRIVATE
#     ${FinalMod_INCLUDE_DIRS}
# )
# target_link_libraries(${MODULE_NAME}
#     ${FinalMod_LIBRARIES}
# )

# FinalMod Test
option(ENABLE_FINALMOD_TEST "Enable building FinalMod test" ON)
if(ENABLE_FINALMOD_TEST)
    function(add_mod_test_config _NAME)
        target_include_directories(${_NAME} PRIVATE
            ${FinalMod_INCLUDE_DIRS}
        )
        target_link_libraries(${_NAME}
            ${FinalMod_LIBRARIES}
        )
    endfunction(add_mod_test_config _NAME)
    add_subdirectory(test/1.finalmod_meta)
    add_subdirectory(test/2.finalmod_wrap)
    add_subdirectory(test/3.helloworld)
    add_subdirectory(test/4.welcome)
endif(ENABLE_FINALMOD_TEST)